import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp

from models.Messages import *
from models.Topics import *
from models.Groups import *
from models.Users import *
from models.Audit import *
from models.Authentication import *
from decorators import *
import logging

class AddNewModerators(webapp.RequestHandler):
  """Class that will be responsible for adding new moderators"""
  def get(self):
    """Render the new_moderator template"""
    # check to make sure the user is allowed to see this
    currUser = get_current_user(self.request)
    # if not currUser.super_user:
      # return self.redirect("/")
    
    flash = None
    template_values = {"flash":flash}
    path= os.path.join(os.path.dirname(__file__), "../templates/super_user.html")
    self.response.out.write(template.render(path, template_values))
    
  def post(self):
    """This will create the new moderators"""
    mod_list = self.request.get("mod_input")
    mod_list = mod_list.strip().split(",")
    
    # loop through all the moderators that were seperated by commas
    for mod in mod_list:
      query = User.all()
      query.filter("email = ", mod)
      
      result = query.get()
      
      # if the email is a valid user then set the moderator proprety to True
      if result:
        result.moderator = True
        result.put()
    return self.redirect("/group")
        
    
